for(i in seq_len(nrow(sparse_points_sf))){
closest[[i]] <- shape_trans[which.min(
st_distance(shape_trans, sparse_points_sf[i,])),]
}
nrow(sparse_points_sf)
sparse_points_sf
dim(sparse_points_sf)
nfeatur(sparse_points_sf)
nrow(sparse_points)
sparse_points
closest <- list()
for(i in seq_len(nrow(sparse_points))){
closest[[i]] <- shape_trans[which.min(
st_distance(shape_trans, sparse_points_sf[i,])),]
}
# find nearest neighbor and extract state name
closest <- list()
for(i in seq_len(nrow(sparse_points))){
closest[[i]] <- shape_trans[which.min(st_distance(shape_trans, sparse_points_sf[i,])),]
}
st_crs(shape_trans)
st_crs(spares_points_sf)
st_crs(sparse_points_sf)
# create a points collection
sparse_points_sf <- do.call("st_sfc",c(lapply(1:nrow(sparse_points),
function(i) {st_point(as.numeric(sparse_points[i, ]))}), list("crs" = 4326)))
class(sparse_points_sf)
str(sparse_points_sf)
sf::st_crs(sparse_points_sf)
# convert to planar
sparse_points_trans <- st_transform(sparse_points_sf, 2163) # apply transformation to pnts sf
sparse_points_trans
nrow(sparse_points_trans)
# find nearest neighbor and extract state name
closest <- list()
for(i in seq_len(nrow(sparse_points))){
closest[[i]] <- shape_trans[which.min(st_distance(shape_trans, sparse_points_trans[i,])),]
}
st_crs(shape_trans)
st_crs(sparse_points_trans)
st_crs(shape_trans) == st_crs(sparse_points_trans)
which.min(st_distance(shape_trans, sparse_points_trans[1,]))
which.min(st_distance(shape_trans, sparse_points_trans[1]))
# find nearest neighbor and extract state name
closest <- list()
for(i in seq_len(nrow(sparse_points))){
closest[[i]] <- shape_trans[which.min(st_distance(shape_trans, sparse_points_trans[i])),]
}
closest <- list()
for(i in 1:2){
closest[[i]] <- shape_trans[which.min(st_distance(shape_trans, sparse_points_trans[i])),]
}
closest
head(shape_trans$DENOMINAZI)
table(shape_trans$DENOMINAZI=="Case sparse")
sparse_shape_trans <- shape trans %>% filter(DENOMINAZI!="Case sparse")
sparse_shape_trans <- shape_trans %>% filter(DENOMINAZI!="Case sparse")
st_crs(sparse_shape_trans) == st_crs(sparse_points_trans)
closest <- list()
for(i in 1:2){
closest[[i]] <- sparse_shape_trans[which.min(st_distance(sparse_shape_trans, sparse_points_trans[i])),]
}
closest
head(case$sparse)
head(case_sparse)
head(sparse_shape_trans)
head(sparse_shape_trans[9])
head(sparse_shape_trans[,9])
head(sparse_shape_trans$DENOMINAZI)
which.col(sparse_shape_trans=="DENOMINAZI")
which(colnames(dsparse_shape_trans)=="DENOMINAZI")
which(colnames(sparse_shape_trans)=="DENOMINAZI")
# find nearest neighbor and extract state name
closest <- list()
for(i in seq_len(nrow(sparse_points))){
closest[[i]] <- sparse_shape_trans[which.min(st_distance(sparse_shape_trans, sparse_points_trans[i])),9]
}
closest
tail(case_sparse)
class(closest)
closest1 <- unnest(closest)
closest1 <- unlist(closest)
head(closest1)
closest1
closest2 <- data.frame(matrix(unlist(closest), nrow=length(closest), byrow=T))
closest2
closest[[1]]
class(closest[[1]])
closest3 <- lapply(closest, st_geometry(nc) <- NULL)
closest3 <- lapply(st_geometry(closest) <- NULL)
class(closest1)
class(closest2)
head(closest2)
closest
class(closest)
closest4 <- do.call(rbind, closest)
head(closest4)
st_geometry(closest4) <- NULL
head(closest4)
closest_comune <- do.call(rbind, closest)
st_geometry(closest_comune) <- NULL
head(closest_comune)
dim(closest_comune)
head(sparse_co)
head(case_sparse)
head(groups_comune)
case_sparse <- cbind(case_sparse, closest_comune)
head(case_sparse)
table(case_sparse$DENOMINAZI)
table(is.na(case_sparse$DENOMINAZI))
case_sparse <- case_sparse %>% dplyr::select(-comune) %>% dplyr::rename(comune=DENOMINAZI)
head(case_sparse)
groups_comune %>% filter(is.na(comune))
# fix NA cases with nearest neighbor
case_NA <- groups_comune %>% filter(is.na(comune))
head(case_NA)
NA_points <- case_NA %>% dplyr::select(lon, lat)
head(NA_points)
NA_points <- filter(lat>=36&lat<=47&lon>=6&long<=18)
NA_points <- NA_points %>% filter(lat>=36&lat<=47&lon>=6&long<=18)
NA_points <- NA_points %>% filter(lat>=36&lat<=47&lon>=6&lon<=18)
head(NA_points)
case_NA <- groups_comune %>% filter(is.na(comune))
head(case_NA)
tail(case_NA)
case_NA <- case_NA %>% filter(lat>=36&lat<=47&lon>=6&lon<=18)
head(case_NA)
# fix NA cases with nearest neighbor
case_NA <- groups_comune %>% filter(is.na(comune))
# drop points outside of italy
#Northernmost point: Westliches Zwillingsköpfl, Predoi, Alto Adige at 47°5′N 12°11′E
#Southernmost point on the mainland: Capo Spartivento, Calabria at 37°56′N 16°3′E; on Lampedusa, Sicily: Punta Pesce Spada, at 35°29′N 12°36′E
#Westernmost point: Rocca Bernauda, Bardonecchia, Piedmont at 45°6′N 6°37′E
#Easternmost point: Capo d'Otranto, Otranto, Apulia at 40°6′N 18°31′E
case_NA <- case_NA %>% filter(lat>=37.5&lat<=47.5&lon>=6.3&lon<=18.3)
head(case_NA)
case_NA <- groups_comune %>% filter(is.na(comune))
# drop points outside of italy
#Northernmost point: Westliches Zwillingsköpfl, Predoi, Alto Adige at 47°5′N 12°11′E
#Southernmost point on the mainland: Capo Spartivento, Calabria at 37°56′N 16°3′E; on Lampedusa, Sicily: Punta Pesce Spada, at 35°29′N 12°36′E
#Westernmost point: Rocca Bernauda, Bardonecchia, Piedmont at 45°6′N 6°37′E
#Easternmost point: Capo d'Otranto, Otranto, Apulia at 40°6′N 18°31′E
case_NA <- case_NA %>% filter(lat>=37.5&lat<=47&lon>=6.3&lon<=18.3)
head(case_NA)
View(case_NA)
case_NA <-  case_NA %>% filter(!grepl("Svizzera",group_name))
case_NA <-  case_NA %>% filter(!grepl("Valais",group_name))
NA_points <- case_NA %>% dplyr::select(lon, lat)
head(NA_points)
# create a points collection
NA_points_sf <- do.call("st_sfc",c(lapply(1:nrow(NA_points),
function(i) {st_point(as.numeric(NA_points[i, ]))}), list("crs" = 4326)))
class(NA_points_sf)
str(NA_points_sf)
sf::st_crs(NA_points_sf)
NA_points_trans <- st_transform(NA_points_sf, 2163) # apply transformation to pnts sf
NA_shape_trans <- shape_trans %>% filter(DENOMINAZI!="Case sparse")
st_crs(NA_shape_trans) == st_crs(NA_points_trans)
# find nearest neighbor and extract state name
closestNA <- list()
for(i in seq_len(nrow(NA_points))){
closestNA[[i]] <- NA_shape_trans[which.min(st_distance(NA_shape_trans, NA_points_trans[i])),9]
}
closest_comune_NA <- do.call(rbind, closestNA)
st_geometry(closest_comune_NA) <- NULL
head(closest_comune_NA)
case_NA <- cbind(case_NA, closest_comune)
case_NA <- cbind(case_NA, closest_comune_NA)
head(case_NA)
case_NA <- cbind(case_NA, closest_comune_NA)
case_NA <- case_NA %>% dplyr::select(-comune) %>% dplyr::rename(comune=DENOMINAZI)
closest_comune_NA <- do.call(rbind, closestNA)
st_geometry(closest_comune_NA) <- NULL
case_NA <- cbind(case_NA, closest_comune_NA)
case_NA <- case_NA %>% dplyr::select(-comune) %>% dplyr::rename(comune=DENOMINAZI)
closest_comune_NA <- do.call(rbind, closestNA)
st_geometry(closest_comune_NA) <- NULL
closest_comune_NA
case_NA <- cbind(case_NA, closest_comune_NA)
head(case_NA)
case_NA <- groups_comune %>% filter(is.na(comune))
# drop points outside of italy
#Northernmost point: Westliches Zwillingsköpfl, Predoi, Alto Adige at 47°5′N 12°11′E
#Southernmost point on the mainland: Capo Spartivento, Calabria at 37°56′N 16°3′E; on Lampedusa, Sicily: Punta Pesce Spada, at 35°29′N 12°36′E
#Westernmost point: Rocca Bernauda, Bardonecchia, Piedmont at 45°6′N 6°37′E
#Easternmost point: Capo d'Otranto, Otranto, Apulia at 40°6′N 18°31′E
case_NA <- case_NA %>% filter(lat>=37.5&lat<=47&lon>=6.3&lon<=18.3)
case_NA <-  case_NA %>% filter(!grepl("Svizzera",group_name))
case_NA <-  case_NA %>% filter(!grepl("Valais",group_name))
case_NA <- cbind(case_NA, closest_comune_NA)
case_NA <- case_NA %>% dplyr::select(-comune) %>% dplyr::rename(comune=DENOMINAZI)
head(case_NA)
# clean original files, no sparse cases, no missings (groups abroad)
groups_match <- groups_comune %>% filter(comune!="Case sparse") %>% filter(!is.na(comune))
head(groups_match)
groups_sparse <- case_sparse
head(groups_sparse)
groups_NA <- case_NA
head(groups_NA)
groups_comune <- rbind(groups_match, groups_sparse)
groups_comune <- rbind(groups_match, groups_sparse)
groups_comune <- rbind(groups_comune, groups_NA)
groups_comune <- groups_comune[,c(1:3,6)]
groups_comune
head(groups_comune)
length(unique(groups_comune$comune))
write.table(groups_comune, paste0(m5spath, "groups_comune.txt"))
write.csv(groups_comune, paste0(m5spath, "groups_comune.csv"))
head(shape)
table(duplicated(shape$DENOMINAZI))
head(meetup)
head(groups_comune)
groups_comune_merge <- groups_comune[,c(1,4)]
groups_comune_merge
events_comune <- merge(meetup, groups_comune_merge, by=c("group_name"))
head(events_comune)
meetup %>% filter(grepl("Tunis", group_name))
meetup %>% filter(grepl("Zurigo", group_name))
meetup %>% filter(grepl("Valais", group_name))
events_comune %>% filter(grepl("Valais", group_name))
events_comune %>% filter(grepl("Tunis", group_name))
write.csv(events_comune, paste0(m5spath, "20190513_events_comune.csv"))
m5s <- read.csv(paste0(m5spath, "20190513_events_comune.csv"))
head(m5s)
m5s$refevent <- ifelse(grepl("referendum", event_description), 1, 0)
m5s$refevent <- ifelse(grepl("referendum", m5s$event_description), 1, 0)
table(m5s$refevent)
m5s %>% filter(refevent==1)
m5s$renzievent <- ifelse(grepl("renzi", m5s$event_description), 1, 0)
table(m5s$renzievent)
names(m5)
names(m5s)
head(m5s$time)
head(m5s)
nr_events <- m5s %>% dplyr::select(local_date, yes_rsvp_count, group_id, comune, refevent, renzievent)
head(nr_events)
class(nr_events$local_date)
nr_events$one <- 1
nr_events$date <- as.Date(nr_events$local_date)
head(nr_events)
nr_com <- nr_events %>%
group_by(comune) %>%
mutate(n_pre2013=sum(one[date<as.Date('2013-01-05']))
nr_com <- nr_events %>%
group_by(comune) %>%
mutate(n_pre2013=sum(one[date<as.Date('2013-01-05')]))
nr_com
View(nr_com)
nr_com <- nr_events %>%
group_by(comune) %>%
mutate(n_pre13=sum(one[date<as.Date('2013-01-05')]),
n_pre16=sum(one[date<as.Date('2016-01-06')]),
n_treat=sum(one[date>as.Date('2016-01-07') & date<as.Date('2016-03-12')]))
head(nr_com)
nr_com <- nr_events %>%
group_by(comune) %>%
mutate(n_pre13=sum(one[date<as.Date('2013-01-05')]),
n_pre16=sum(one[date<as.Date('2016-06-01')]),
n_treat=sum(one[date>as.Date('2016-07-01') & date<as.Date('2016-12-03')]))
head(nr_com)
View(nr_com)
table(is.na(nr_event$one))
table(is.na(nr_events$one))
table(is.na(nr_events$date))
filter(nr_events,(is.na($date))
filter(nr_events,(is.na(date))
)
table(is.na(m5s$local_date))
m5s %>% filter(is.na(m5s$local_date))
)
m5s %>% filter(is.na(m5s$local_date))
nr_com <- nr_events %>% filter(!is.na(date)) %>%
group_by(comune) %>%
mutate(n_pre13=sum(one[date<as.Date('2013-01-05')]),
n_pre16=sum(one[date<as.Date('2016-06-01')]),
n_treat=sum(one[date>as.Date('2016-07-01') & date<as.Date('2016-12-03')]))
head(nr_com)
nr_com <- nr_events %>% filter(!is.na(date)) %>%
group_by(comune) %>%
mutate(n_total=sum(one),
n_pre13=sum(one[date<as.Date('2013-01-05')]),
n_pre16=sum(one[date<as.Date('2016-06-01')]),
n_treat=sum(one[date>as.Date('2016-07-01') & date<as.Date('2016-12-03')]))
nr_com
nr_com <- nr_events %>% filter(!is.na(date)) %>%
group_by(comune) %>%
mutate(n_total=sum(one),
n_pre13=sum(one[date<as.Date('2013-01-05')]),
n_pre16=sum(one[date<as.Date('2016-06-01')]),
n_treat=sum(one[date>as.Date('2016-07-01') & date<as.Date('2016-12-04')]))
hist(nr_com$n_treat)
nr_com <- nr_events %>% filter(!is.na(date)) %>%
group_by(comune) %>%
mutate(n_total=sum(one),
n_pre13=sum(one[date<as.Date('2013-01-05')]),
n_pre16=sum(one[date<as.Date('2016-06-01')]),
n_treat=sum(one[date>as.Date('2016-07-01') & date<as.Date('2016-12-04')]),
n_treat_ref=sum(refevent[date>as.Date('2016-07-01') & date<as.Date('2016-12-04')]),
n_treat_renzi=sum(renzievent[date>as.Date('2016-07-01') & date<as.Date('2016-12-04')])
)
nr_com
nr_com
View(nr_com)
nr_com <- nr_events %>% filter(!is.na(date)) %>%
group_by(comune) %>%
mutate(n_total=sum(one),
n_pre13=sum(one[date<as.Date('2013-01-05')]),
n_pre16=sum(one[date<as.Date('2016-06-01')]),
n_treat=sum(one[date>as.Date('2016-07-01') & date<as.Date('2016-12-04')]),
n_treat_ref=sum(refevent[date>as.Date('2016-07-01') & date<as.Date('2016-12-04')]),
n_treat_renzi=sum(renzievent[date>as.Date('2016-07-01') & date<as.Date('2016-12-04')])
) %>%
# transform to comune-level data
filter(row_number(one) == 1)
View(nr_com)
nr_com <- nr_events %>% filter(!is.na(date)) %>%
group_by(comune) %>%
mutate(n_total=sum(one),
# total number of events per comune
n_pre13=sum(one[date<as.Date('2013-01-05')]),
# nr of events for specific time periods
n_pre16=sum(one[date<as.Date('2016-06-01')]),
n_treat=sum(one[date>as.Date('2016-07-01') & date<as.Date('2016-12-04')]),
# nr of events in treatment period with reference to either referendum or renzi
n_treat_ref=sum(refevent[date>as.Date('2016-07-01') & date<as.Date('2016-12-04')]),
n_treat_renzi=sum(renzievent[date>as.Date('2016-07-01') & date<as.Date('2016-12-04')]),
# nr of events weighted by rsvp
n_pre13=sum((one*yes_rsvp_count)[date<as.Date('2013-01-05')]),
# nr of events for specific time periods
n_pre16=sum((one*yes_rsvp_count)[date<as.Date('2016-06-01')]),
n_treat=sum((one*yes_rsvp_count)[date>as.Date('2016-07-01') & date<as.Date('2016-12-04')]),
)
head(nr_com)
nr_com <- nr_events %>% filter(!is.na(date)) %>%
group_by(comune) %>%
mutate(n_total=sum(one),
# total number of events per comune
n_pre13=sum(one[date<as.Date('2013-01-05')]),
# nr of events for specific time periods
n_pre16=sum(one[date<as.Date('2016-06-01')]),
n_treat=sum(one[date>as.Date('2016-07-01') & date<as.Date('2016-12-04')]),
# nr of events in treatment period with reference to either referendum or renzi
n_treat_ref=sum(refevent[date>as.Date('2016-07-01') & date<as.Date('2016-12-04')]),
n_treat_renzi=sum(renzievent[date>as.Date('2016-07-01') & date<as.Date('2016-12-04')]),
# nr of events weighted by rsvp
wn_pre13=sum((one*yes_rsvp_count)[date<as.Date('2013-01-05')]),
# nr of events for specific time periods
wn_pre16=sum((one*yes_rsvp_count)[date<as.Date('2016-06-01')]),
wn_treat=sum((one*yes_rsvp_count)[date>as.Date('2016-07-01') & date<as.Date('2016-12-04')]),
)
head(nr_com)
nr_com <- nr_events %>% filter(!is.na(date)) %>%
group_by(comune) %>%
mutate(n_total=sum(one),
# total number of events per comune
n_pre13=sum(one[date<as.Date('2013-01-05')]),
# nr of events for specific time periods
n_pre16=sum(one[date<as.Date('2016-06-01')]),
n_treat=sum(one[date>as.Date('2016-07-01') & date<as.Date('2016-12-04')]),
# nr of events in treatment period with reference to either referendum or renzi
n_treat_ref=sum(refevent[date>as.Date('2016-07-01') & date<as.Date('2016-12-04')]),
n_treat_renzi=sum(renzievent[date>as.Date('2016-07-01') & date<as.Date('2016-12-04')]),
# nr of events weighted by rsvp
wn_total=sum(one*yes_rsvp_count),
wn_pre13=sum((one*yes_rsvp_count)[date<as.Date('2013-01-05')]),
wn_pre16=sum((one*yes_rsvp_count)[date<as.Date('2016-06-01')]),
wn_treat=sum((one*yes_rsvp_count)[date>as.Date('2016-07-01') & date<as.Date('2016-12-04')]),
)
nr_com
min(nr_com$n_total)
nr_com %>% filter(n_total==1)
nr_com %>% filter(n_total==1)
nr_com %>% filter(n_total==4)
nr_com <- nr_events %>% filter(!is.na(date)) %>%
group_by(comune) %>%
mutate(n_total=sum(one),
# total number of events per comune
n_pre13=sum(one[date<as.Date('2013-01-05')]),
# nr of events for specific time periods
n_pre16=sum(one[date<as.Date('2016-06-01')]),
n_treat=sum(one[date>as.Date('2016-07-01') & date<=as.Date('2016-12-04')]),
# nr of events in treatment period with reference to either referendum or renzi
n_treat_ref=sum(refevent[date>as.Date('2016-07-01') & date<=as.Date('2016-12-04')]),
n_treat_renzi=sum(renzievent[date>as.Date('2016-07-01') & date<=as.Date('2016-12-04')]),
# post referendum
n_posttreat=sum(one[date>as.Date('2016-12-04')]),
# nr of events weighted by rsvp
wn_total=sum(one*yes_rsvp_count),
wn_pre13=sum((one*yes_rsvp_count)[date<as.Date('2013-01-05')]),
wn_pre16=sum((one*yes_rsvp_count)[date<as.Date('2016-06-01')]),
wn_treat=sum((one*yes_rsvp_count)[date>as.Date('2016-07-01') & date<=as.Date('2016-12-04')]),
wn_treat_ref=sum((refevent*yes_rsvp_count)[date>as.Date('2016-07-01') & date<=as.Date('2016-12-04')]),
wn_treat_renzi=sum((renzievent*yes_rsvp_count)[date>as.Date('2016-07-01') & date<=as.Date('2016-12-04')]),
n_posttreat=sum((one*yes_rsvp_count)[date>as.Date('2016-12-04')])
)
nr_com %>% filter(n_total==4)
nr_com %>% filter(n_total==4)
nr_com <- nr_events %>% filter(!is.na(date)) %>%
group_by(comune) %>%
mutate(n_total=sum(one),
# total number of events per comune
n_pre13=sum(one[date<as.Date('2013-01-05')]),
# nr of events for specific time periods
n_pre16=sum(one[date<as.Date('2016-06-01')]),
n_treat=sum(one[date>as.Date('2016-07-01') & date<=as.Date('2016-12-04')]),
# nr of events in treatment period with reference to either referendum or renzi
n_treat_ref=sum(refevent[date>as.Date('2016-07-01') & date<=as.Date('2016-12-04')]),
n_treat_renzi=sum(renzievent[date>as.Date('2016-07-01') & date<=as.Date('2016-12-04')]),
# post referendum
n_posttreat=sum(one[date>as.Date('2016-12-04')]),
# nr of events weighted by rsvp
wn_total=sum(one*yes_rsvp_count),
wn_pre13=sum((one*yes_rsvp_count)[date<as.Date('2013-01-05')]),
wn_pre16=sum((one*yes_rsvp_count)[date<as.Date('2016-06-01')]),
wn_treat=sum((one*yes_rsvp_count)[date>as.Date('2016-07-01') & date<=as.Date('2016-12-04')]),
wn_treat_ref=sum((refevent*yes_rsvp_count)[date>as.Date('2016-07-01') & date<=as.Date('2016-12-04')]),
wn_treat_renzi=sum((renzievent*yes_rsvp_count)[date>as.Date('2016-07-01') & date<=as.Date('2016-12-04')]),
wn_posttreat=sum((one*yes_rsvp_count)[date>as.Date('2016-12-04')])
)
nr_com %>% filter(n_total==4)
nr_com %>% filter(n_total==4) %>% print(n=100)
nr_com %>% filter(n_total==7) %>% print(n=7)
nr_com %>% filter(n_total==17) %>% print(n=17)
nr_com <- nr_events %>% filter(!is.na(date)) %>%
group_by(comune) %>%
mutate(n_total=sum(one),
# total number of events per comune
n_pre13=sum(one[date<as.Date('2013-01-05')]),
# nr of events for specific time periods
n_pre16=sum(one[date<as.Date('2016-06-01')]),
n_treat=sum(one[date>as.Date('2016-07-01') & date<=as.Date('2016-12-04')]),
# nr of events in treatment period with reference to either referendum or renzi
n_treat_ref=sum(refevent[date>as.Date('2016-07-01') & date<=as.Date('2016-12-04')]),
n_treat_renzi=sum(renzievent[date>as.Date('2016-07-01') & date<=as.Date('2016-12-04')]),
# post referendum
n_posttreat=sum(one[date>as.Date('2016-12-04')]),
# nr of events weighted by rsvp
wn_total=sum(one*yes_rsvp_count),
wn_pre13=sum((one*yes_rsvp_count)[date<as.Date('2013-01-05')]),
wn_pre16=sum((one*yes_rsvp_count)[date<as.Date('2016-06-01')]),
wn_treat=sum((one*yes_rsvp_count)[date>as.Date('2016-07-01') & date<=as.Date('2016-12-04')]),
wn_treat_ref=sum((refevent*yes_rsvp_count)[date>as.Date('2016-07-01') & date<=as.Date('2016-12-04')]),
wn_treat_renzi=sum((renzievent*yes_rsvp_count)[date>as.Date('2016-07-01') & date<=as.Date('2016-12-04')]),
wn_posttreat=sum((one*yes_rsvp_count)[date>as.Date('2016-12-04')])
) %>%
# transform to comune-level data
filter(row_number(one) == 1)
hist(nr_com$wn_treat)
hist(nr_com$wn_treat, breaks=50)
hist(nr_com$n_treat, breaks=50)
nr_com %>% filter(n_treat>800)
nr_com %>% filter(n_treat>500)
nr_com %>% filter(n_treat>400)
nr_com %>% filter(n_treat>100)
pop <- read.csv(paste0(m5spath, popfile, ".csv"))
popfile <- "DCIS_POPRES1_13052019234604839"
pop <- read.csv(paste0(m5spath, popfile, ".csv"))
head(pop)
table(pop$ITTER107)
head(pop)
table(pop$Sesso)
table(pop$ETA1)
popfile <- "DCIS_POPRES1_13052019235616360"
pop <- read.csv(paste0(m5spath, popfile, ".csv"))
head(pop)
table(pop$TIPO_DATO15)
table(pop$SEXISTAT1)
table(pop$Sesso)
pop <- pop %>% select(ITTER107, Territorio, Value) %>% rename(comune_code=ITTER107, comune=Territorio, pop=Value)
head(pop)
pop <- pop %>% select(ITTER107, Territorio, Value) %>% rename(comune_code=ITTER107, comune=Territorio, pop=Value) %>% filter(comune!="Italia")
pop <- read.csv(paste0(m5spath, popfile, ".csv"))
pop <- pop %>% select(ITTER107, Territorio, Value) %>%
rename(comune_code=ITTER107, comune=Territorio, pop=Value) %>%
filter(comune!="Italia")
head(pop)
max(pop$pop)
filter(pop, pop==max(pop))
nr_com_pop <- merge(nr_com, pop, by=c("comune"), all.x=TRUE)
head(nr_com_pop)
table(is.na(nr_com_pop$pop))
nr_com_pop %>% filter(is.na(pop))
"Bolzano" %in% pop$comune
View(pop)
table(is.na(nr_com_pop$pop))
head(nr_com_pop)
nr_com_pop
nr_com_pop %>% filter(comune=="Vicenza")
nr_com_pop %>% filter(comune=="San Paolo di Civitate")
nr_com_pop %>% filter(comune=="Legnaro")
nr_com_pop %>% filter(comune=="Trieste")
nr_com_pop %>% filter(comune=="Verona")
nr_com_pop %>% filter(comune=="Bacoli")
nr_com_pop %>% filter(comune=="Rio Saliceto")
nr_com_pop %>% filter(comune=="Turriaco")
nr_com_pop %>% filter(comune=="Agrigento")
nr_com_pop %>% filter(comune=="Montefelcino")
nr_com_pop %>% filter(comune=="Lodrino")
nr_com_pop %>% filter(comune=="Sequals")
nr_com_pop %>% filter(comune=="Voghera")
setwd("~/Dropbox/projects/m5S/data/ITANES_PRE-POST_Referendum_2016")
panelpath <- "~/Dropbox/projects/m5S/data/ITANES_PRE-POST_Referendum_2016/"
panel <- read.dta13(paste0(panelpath, "itanes_referndum_panel.dta"))
panelpath
panel <- read.dta13(paste0(panelpath, "itanes_referendum_panel.dta"))
head(panel$comune_1)
?setdiff
table(panel$comune_1 %in% nr_com_pop$comune)
table(nr_com_pop$comune %in% panel$comune_1)
write.csv(nr_com_pop, paste0(m5spath, "events_comune.csv"))
5612 / 6588
head(nr_com_pop)
